<!-- Author:Rain -->
<template>
    <h1>自定义的customRef()</h1>
    <input type="text" v-model="msg">
</template>

<script setup lang="js">
import {ref,customRef } from "vue"
// const msg=ref("xix")
const msg=useReplaceRef("xiaoyu")

function useReplaceRef(value) {
  return customRef((track, trigger) => {
    return {
      get() {
        track()
        return value
      },
      set(newValue) {
        //这里更改数据
        value = replaceStr(newValue)
          trigger()
      }
    }
  })
}

function replaceStr(str){
    let whiteList=["sb","SB"]
    whiteList.forEach((item)=>{
        str=str.replace(item,"**")
    })
    return str
}


</script>


<style scoped>

</style>